from django.db import models

# Create your models here.


class Catalog(models.Model):
    name = models.CharField("类别名称", max_length=20, null=False)

    class Meta:
        db_table = 'catalog'

    def __str__(self):
        return f"{self.id}--{self.name}"


class Brand(models.Model):
    name = models.CharField("品牌名称", max_length=20, null=False)

    class Meta:
        db_table = 'brand'

    def __str__(self):
        return f"{self.id}--{self.name}"


class SPU(models.Model):
    name = models.CharField("商品名词", max_length=50)
    sales = models.IntegerField("销量", default=0)
    comments = models.IntegerField("评价数", default=0)
    brand = models.ForeignKey(Brand, on_delete=models.CASCADE)
    catalog = models.ForeignKey(Catalog, on_delete=models.CASCADE)

    class Meta:
        db_table = "spu"

    def __str__(self):
        return f"{self.id}--{self.name}"